﻿// 简易矢量图生成模型.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <vector>
#include "CShape.h"
#include "鼠标操作集合.h"
#include "智能指针.hpp"

//测试鼠标框选实现
void test01() {//实现三次鼠标框选测试
	initgraph(640, 480);
	IMAGE tmp;
	for(int i = 0; i < 3;)
		if (Getimage(&tmp))
			i++;
	_getch();
	closegraph();
}
//测试智能指针实现
void test02() {
	cout << "智能指针生成" << endl;
	{
		AutoPtr<POINT> titi = new POINT({ 10,20 });
		//cout << titi.m_num << '\t' << *titi.m_num << endl;
		//cout << titi.m_ptr << '\t' << (*titi.m_ptr).x << endl;
		AutoPtr<POINT> riri = titi;
		//cout << titi.m_num << '\t' << *titi.m_num << endl;
		//cout << titi.m_ptr << '\t' << titi->x << endl;
	}
}
//测试读取n个点实现
void test03() {
	initgraph(640, 480);
	int n = 0;
	AutoPtr<POINT> pPoint = getPoints(n);
	cout << n << "个点坐标:" << endl;
	for (int i = 0; i < n; ++i) {
		cout << "第" << i+1 << "个点：" << pPoint[i].x << " " << pPoint[i].y << endl;
	}
	_getch();
	closegraph();
}
//测试各类的功能
void test04() {
	initgraph(640, 480);
	//vector维护智能指针，指针维护CShape类
	vector<AutoPtr<CShape>> All_Graphics;
	vector<AutoPtr<CShape>>::iterator it;
	All_Graphics.reserve(100);
	AutoPtr<CShape> C_Ptr;
	POINT pts[4] = { {0,0},{100,100},{20,20},{100,100} };
	/*********************************
	* CStraightline直线类，通过两点确定
	* id 为 1
	*********************************/
	C_Ptr = new CStraightline({ 30,25 }, { 80,70 });
	All_Graphics.push_back(C_Ptr);
	
	it = All_Graphics.begin();
	(*it)->draw();
	//(*it)->setPoint(1, pts[2]);
	(*it)->drawColor();
	cout << (*it)->getLength() << ' ';
	C_Ptr = (*it)->copy();
	cout << (*it)->ifShapeIn(CRectangle({20,20},{100,100})) << ' ';
	cout << (*it)->ifShapeIn(pts[2],pts[3]) << ' ';
	(*it)->move(50, 50);
	(*it)->draw();
	cout << (*it)->getPoint(1).x << ' ' << (*it)->getPoint(1).y;
	
	All_Graphics.push_back(C_Ptr);

	/*
	破案了！迭代器容量改变导致迭代器失效	
	//	//it = All_Graphics.begin();
	//	it = All_Graphics.erase(it);//这句话会报错，越界
	//	All_Graphics.erase(All_Graphics.begin());//这句不会
	*/

	_getch();
	closegraph();
}
//创建动画的鼠标操作测试
void test05() {
	initgraph(640, 480);
	
	setlinecolor(WHITE);
	AutoPtr<CShape> ptr;//智能指针接口，用于管理矢量图
	
	OPERATOR = c_Triangle;
	ptr = createSP.select();
	_getch();

	OPERATOR = c_Straight;
	ptr = createSP.select();
	_getch();

	//OPERATOR = c_Polygon;
	//ptr = createSP.select();
	//_getch();
	
	closegraph();
}

int main()
{
	test05();
	return 0;
}
